import time


class Timer:
    def __init__(self):
        self.elasped = 0

    def __enter__(self):
        self.start = time.perf_counter()
        return self

    def __exit__(self, type, value, traceback):
        self.end = time.perf_counter()
        self.elasped = self.end - self.start
        print(f"函数运行时间为 {self.elasped} 秒")


def c():
    with Timer():
        count = 0
        for i in range(10000000):
            count += 1
        print(count)


if __name__ == '__main__':
    c()
